package com.xiaojun.whut.Service.Impl;

import com.xiaojun.whut.Entity.Comment;
import com.xiaojun.whut.Repository.CommentRepository;
import com.xiaojun.whut.Service.CommentService;
import com.xiaojun.whut.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    private Logger logger= LoggerFactory.getLogger(getClass());
    @Autowired
    private CommentRepository commentRepository;
    @Override
    public Object save(Comment comment) {
        if(comment ==null){
            return ResponseUtil.badArgument();
        }
        try {
            commentRepository.save(comment);
        }catch (Exception e){
            logger.debug(e.getMessage());
            return ResponseUtil.fail(133,e.getMessage());
        }
        return ResponseUtil.ok();
    }

    @Override
    public Object getAllbyCardMessageId(int cardMessageId) {
        List<Comment> commentList=commentRepository.findByCardMessageId(cardMessageId);
        return commentList;
    }
}
